//
//  AIFSetPwdManager.m
//  PywSdk
//
//  Created by smallwave on 16/8/9.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "AIFSetPwdManager.h"
#import "PywRSAUtil.h"
#import "PywSdk+login.h"

@implementation AIFSetPwdManager

NSString *const SetPwd_PASSPORT_TOKEN = @"passport_token";
NSString *const SetPwd_PASSPORT = @"passport";
NSString *const SetPwd_PASSWORD = @"password";
NSString *const SetPwd_TID = @"tid";
NSString *const SetPwd_GAMEID = @"gameid";
NSString *const SetPwd_SMSTYPE = @"smstype";
NSString *const SetPwd_SMSCODE = @"smscode";
NSString *const SetPwd_ISCHECKSMSCODE = @"is_check_smscode";
NSString *const SetPwd_SIGN = @"sign";

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.child = self;
        self.paramSource = self;
        self.validate = self;
    }
    return self;
}


#pragma mark - ETAPIManager
- (NSString *)methodName
{
    return URL_CHANGEPWD;
}

- (ETAPIManagerRequestType)requestType
{
    return ETAPIManagerRequestTypePost;
}


- (NSString *)seriviceType
{
    return [PywAppInfo sharedAppInfo].seriviceType;
}


#pragma mark - ETAPIManagerParamSourceDelegate
- (NSDictionary *)paramsForApi:(ETApiBaseManager *)manager
{
    NSString * passport = self.passport;
    NSString * smstype = self.smstype;
    NSString * smscode = self.smscode;
    NSString * is_check_smscode = self.is_check_smscode;
    
    NSString *tid = [PywAppInfo sharedAppInfo].tid;
    NSString * apiSecret2 = [AppUtil getApiSecret2:tid apiSecret:[PywAppInfo sharedAppInfo].apisecret];
    
    NSString *sign = [NSString stringWithFormat:@"%@%@%@%@", passport,smstype,self.password,apiSecret2];
    sign = [PywCipherUtils md5:sign];
    
    NSString * gameid = [PywAppInfo sharedAppInfo].gameId;
    NSString * password = [PywRSAUtil encryptString:self.password];
    
    MutableDictionary *param = [[MutableDictionary alloc] init];
    if ([PywSdk manger].isLogined) {
        NSString *passport_token = [PywPlatformMain sharedPlatformMain].passport_Token;
        [param setObject:passport_token forKey:SetPwd_PASSPORT_TOKEN];
    }
    [param setObject:passport forKey:SetPwd_PASSPORT];
    [param setObject:password forKey:SetPwd_PASSWORD];
    [param setObject:smstype forKey:SetPwd_SMSTYPE];
    [param setObject:smscode forKey:SetPwd_SMSCODE];
    [param setObject:is_check_smscode forKey:SetPwd_ISCHECKSMSCODE];
    [param setObject:tid forKey:SetPwd_TID];
    [param setObject:sign forKey:SetPwd_SIGN];
    [param setObject:gameid forKey:SetPwd_GAMEID];
    return param;
}

#pragma mark - ETAPIManagerValidator
- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithParamsData:(NSDictionary *)data{
    return YES;
}

- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithCallBackData:(NSDictionary *)data{
    return YES;
}


@end
